package org.example;

import java.io.*;

public class demo4 {
    public static void main(String[] args) throws IOException {
    /*字节缓冲流：加快拷贝速度*/

 /*   //创建缓冲流对象
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream("b.txt"));
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("c.txt"));
    //循环读取
        int b;
        while ((b = bis.read()) != -1){
            bos.write(b);
        }
   //释放资源
        bos.close();
        bis.close();
*/

        /*
        * 定义数组，多个字节拷贝
        * */
       /* BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream("b.txt"));
        BufferedOutputStream bos1 = new BufferedOutputStream(new FileOutputStream("c.txt"));
        //循环读取
        byte[] bytes = new byte[20];
        int len;
        while ((len = bis1.read(bytes)) != -1){
            bos1.write(bytes,0,len);
        }
        bos1.close();
        bis1.close();*/


        /*字符缓冲流*/
         /*输入流*/
        //特有方法 readLine
        BufferedReader bis2 = new BufferedReader(new FileReader("b.txt"));
        //读取数据
        /*String line = bis2.readLine();
        System.out.println(line);*/
        //循环读取
       String line;
       while (((line = bis2.readLine())!= null)){
           System.out.println(line);
       }
        bis2.close();


       /*字符缓冲输出流*/
        BufferedWriter bw = new BufferedWriter(new FileWriter("d.txt",true));
        //写数据
        bw.write("123");
        bw.newLine();
        bw.write("456");
        bw.newLine();
        //释放资源
        bw.close();
    }
}
